/**
 * 
 */
package us.gaaoc.framework.dao;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.Query;

import java.util.GregorianCalendar;

import org.apache.log4j.Logger;


import us.gaaoc.framework.model.Documents;
import us.gaaoc.framework.model.Person;
import us.gaaoc.framework.model.Signatures;
import us.gaaoc.framework.util.HelperClass;

/**
 * @author Sukahda Tapshalkar
 * Aug 16, 2006
 *
 */
public class SignaturesDAOHibernate extends
GenericHibernateDAO<Signatures, String, SignaturesDAO> implements
SignaturesDAO  {
	
	Logger LOG = Logger.getLogger(SignaturesDAOHibernate.class);

	protected SignaturesDAOHibernate() {}
	
//	 added M Alexandrou
	public List<Signatures> findSignaturesByDocumentsUuid(String docUuid){
		Query q = this.getSession().createQuery("from Signatures sig where sig.documentUuid = ?");
		q.setString(0, docUuid);	
		return q.list();
	}

	public Signatures findSignaturesByDocumentsUuidAndSignerUuid(String docUuid, String personUuid) {
		return null;
	}

	public boolean isSignaturesByDocumentsUuidAndPersonUuid(String docUuid, String personUuid) {
		LOG.info("Inside the findSignaturesByDocumentsUuidAndPersonUuid method of the SignaturesDAOHibernate  .....");
		Query q = this.getSession().createQuery("from Signatures sig where sig.documentUuid = ? and sig.signedByPersonUuid = ? ");
		q.setString(0, docUuid);
		q.setString(1, personUuid);
		if(q.list()==null){
			LOG.info("Inside the findSignaturesByDocumentsUuidAndPersonUuid method of the SignaturesDAOHibernate and the query is returns......");
			return false;
		}else{
			return true;
		}
	}

	public Signatures findSignatureFromSignatureTrackingID(String sigTrackingId) {
		Query q = this.getSession().createQuery("from Signatures sig where sig.signatureTrackingId = ? ");
		q.setString(0, sigTrackingId);
		return (Signatures)q.uniqueResult();
	}
 // Added by Bhawana 
	public int CountSignaturesByAttorney() {
		String sql="SELECT COUNT(uuid) FROM signatures WHERE personUuid='attorneyUuid2'";
		Query q = getSession().createSQLQuery(sql);
		List l = q.list();
		BigInteger tempResultSize = (BigInteger) l.get(0);
		int resultSetSize = tempResultSize.intValue();
		return resultSetSize;
	}

	public int countSignatureByCourtClerk() {
		String sql="SELECT COUNT(uuid) FROM signatures WHERE personUuid='clerkUuid2' OR personUuid='clerkUuid5';";
		Query q = getSession().createSQLQuery(sql);
		List l = q.list();
		BigInteger tempResultSize = (BigInteger) l.get(0);
		int resultSetSize = tempResultSize.intValue();
		return resultSetSize;
	}

	public int countSignatures() {
		String sql="SELECT COUNT(uuid) FROM signatures;";
		Query q = getSession().createSQLQuery(sql);
		List l = q.list();
		BigInteger tempResultSize = (BigInteger) l.get(0);
		int resultSetSize = tempResultSize.intValue();
		return resultSetSize;
	}
	public int countSignaturesByJudge() {
		String sql="SELECT COUNT(uuid) FROM signatures WHERE   personUuid='judgeUuid2'";
		Query q = getSession().createSQLQuery(sql);
		List l = q.list();
		BigInteger tempResultSize = (BigInteger) l.get(0);
		int resultSetSize = tempResultSize.intValue();
		return resultSetSize;
	}

}
